//
//  NSString+Helper.m
//  RLExample
//
//  Created by zaishengzheng on 16/3/8.
//  Copyright (c) 2016年 Mr.zheng. All rights reserved.
//

#import "NSString+Helper.h"
#import <CommonCrypto/CommonDigest.h>
#import "pinyin.h"
#import "SCConstants.h"
#import "Config.h"

@implementation NSString (Helper)

+ (BOOL)SC_isBlankString:(NSString *)string {
    if(!string){
        return YES;
    }
    if([string isKindOfClass:[NSNumber class]]||[string isKindOfClass:[NSArray class]]||[string isKindOfClass:[NSDictionary class]]){
        return NO;
    }

    if (string == nil || string == NULL) {
        return YES;
    }
    if(![string isKindOfClass:[NSString class]]){
        return NO;
    }
    if(!string.length){
        return YES;
    }
    if([string isEqualToString:@""]){
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if([string isEqualToString:@"null"]){
        return YES;
    }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0) {
        return YES;
    }
    
    return NO;
}

- (id)jsonObject{
    if([self isKindOfClass:[NSNull class]])
        return nil;
    NSData *data = [self dataUsingEncoding:4];
    NSError *error = nil;
    id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
    if(error){
        return nil;
    }else{
        return obj;
    }
}


+(NSString *)SC_trimString:(NSString*)string{
    if(string == nil|| string == NULL){
        return @"";
    }
    if([string isKindOfClass:[NSNull class]]){
        return @"";
    }
    if([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0){
        return @"";
    }
    return [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
+ (NSString *)SC_trimStringToNil:(NSString *)string{
    if(string == nil|| string == NULL){
        return nil;
    }
    if([string isKindOfClass:[NSNull class]]){
        return nil;
    }
    if([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0){
        return nil;
    }
    return [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

- (NSString *)md5String{
    NSParameterAssert(self);
    const char *cStr = [self UTF8String];
    unsigned char result[16];
    CC_MD5(cStr, (CC_LONG)strlen(cStr), result); // This is the md5 call
    NSString * md5_result = [NSString stringWithFormat:
                         @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
                         result[0], result[1], result[2], result[3],
                         result[4], result[5], result[6], result[7],
                         result[8], result[9], result[10], result[11],
                         result[12], result[13], result[14], result[15]
                         ];
    return [md5_result uppercaseString] ;
}

+ (NSString *)UUIDString{
    NSString *UUIDString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, CFUUIDCreate(kCFAllocatorDefault)));
    return [UUIDString lowercaseString];
}

+ (BOOL)SC_isValidatedPhone:(NSString *)phone{
    if([self SC_isBlankString:phone])return NO;
    phone = [self SC_trimString:phone];
     NSString *phoneRegex = @"^\\d{11}$";
    NSPredicate *phonePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phonePredicate evaluateWithObject:phone];
}

+ (BOOL)SC_isValidatedVerificationCode:(NSString *)code{
    if([self SC_isBlankString:code])return NO;
    code = [self SC_trimString:code];
    NSString *codeRegex = @"^\\d{4}$";
    NSPredicate *codePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",codeRegex];
    return [codePredicate evaluateWithObject:code];
}

+ (NSString *)imageNamedUUIDPath{
    NSString *imageSavedFilePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    return [imageSavedFilePath stringByAppendingString:[NSString stringWithFormat:@"/%@.png", [[self UUIDString] stringByReplacingOccurrencesOfString:@"-" withString:@""]]];
}

+ (NSString *)imageTempPathByUUID{
    NSString *imageSavedFilePath = NSTemporaryDirectory();
    return [imageSavedFilePath stringByAppendingString:[NSString stringWithFormat:@"/%@.png", [[self UUIDString] stringByReplacingOccurrencesOfString:@"-" withString:@""]]];
}

+ (NSString *)topRecommendPlistPath{
      NSString *plistPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    return [plistPath stringByAppendingPathComponent:@"topRecommend.data"];
}

+ (NSString *)hotRecommendPlistPath{
    NSString *plistPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    return [plistPath stringByAppendingPathComponent:@"hotRecommend.data"];
}

+ (NSString *)SC_formatFromDate:(NSDate *)date{
     NSString *dateStr = nil;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSTimeInterval oInterval = [date timeIntervalSince1970];
    NSDate *currentDate = [NSDate date];
    NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:currentDate];
    [components setHour:0];
    [components setMinute:0];
    [components setSecond:0];
    NSTimeInterval cInterval =  [[calendar dateFromComponents:components] timeIntervalSince1970];
    if((oInterval - cInterval >=0)&&(oInterval - cInterval<=24*60*60)){
        [dateFormatter setDateFormat:@"a HH:mm"];
    }else{
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    }
     dateStr = [dateFormatter stringFromDate:date];
    return dateStr;
}

+ (NSString *)SC_abbreviationDateString:(NSString*)dateString{
    @try{

        NSArray *components = [dateString componentsSeparatedByString:@" "];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *date = [dateFormatter dateFromString:dateString];
        if(components.count>=1){
            dateString = components[0];
        }
        NSString *dateStr = nil;
        NSDate *curDate = [NSDate date];
      
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSString *curDateStr = [dateFormatter stringFromDate:curDate];
        if([dateString isEqualToString:curDateStr]){
            [dateFormatter setDateFormat:@"a HH:mm"];
            dateStr = [dateFormatter stringFromDate:date];
        }else{
            [dateFormatter setDateFormat:@"MM-dd"];
            dateStr = [dateFormatter stringFromDate:date];
        }
        return dateStr;
    }@catch(NSException *exception) {
        return @"";
    }
}

+ (NSString *)SC_stringFromBeijingDate:(NSDate *)date{
     @try {
    NSString *dateStr = nil;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSTimeInterval oInterval = [date timeIntervalSince1970];
    NSTimeInterval cInterval = [[NSDate date] timeIntervalSince1970];
    NSTimeInterval diff = cInterval - oInterval;
    NSDate *oDate = [NSDate dateWithTimeIntervalSince1970:oInterval];
    NSDate *cDate = [NSDate dateWithTimeIntervalSince1970:cInterval];
    if(diff <=60){
      dateStr = @"刚刚";
    }else if (diff<=60*60){
        int mins = diff/60;
        dateStr = [NSString stringWithFormat:@"%d分钟前",mins];
    }else if(diff<=60*60*24){  //在两天内的
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        [dateFormatter setDateFormat:@"HH:mm"];
        NSString * oDateString = [dateFormatter stringFromDate:oDate];
        NSString *cDateString = [dateFormatter stringFromDate:cDate];
        if([oDateString isEqualToString:cDateString]){
           dateStr = [NSString stringWithFormat:@"今天 %@",[dateFormatter stringFromDate:oDate]];
        }else{
           dateStr = [NSString stringWithFormat:@"昨天 %@",[dateFormatter stringFromDate:oDate]];
        }
    }else{
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        dateStr = [dateFormatter stringFromDate:oDate];
    }
    return dateStr;
     }@catch(NSException *exception) {
         return @"";
     }
}

+ (NSString *)dateStringDate:(NSDate *)date {
    @try {
        // ------实例化一个NSDateFormatter对象
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//这里的格式必须和DateString格式一致
//
        NSDate * nowDate = [NSDate date];
        
        // ------将需要转换的时间转换成 NSDate 对象
//        NSDate * needFormatDate = [dateFormatter dateFromString:dateString];
        NSDate *needFormatDate = date;
        // ------取当前时间和转换时间两个日期对象的时间间隔
        NSTimeInterval time = [nowDate timeIntervalSinceDate:needFormatDate];
        
        NSLog(@"time----%f",time);
        // ------再然后，把间隔的秒数折算成天数和小时数：
        
        NSString *dateStr = [[NSString alloc] init];
        
        if (time<=60) {  //1分钟以内的
            
            dateStr = @"刚刚";
            
        }else if(time<=60*60){  //一个小时以内的
            
            int mins = time/60;
            dateStr = [NSString stringWithFormat:@"%d分钟前",mins];
            
        }else if(time<=60*60*24){ //在两天内的
            int hour = time/60/60;
            dateStr = [NSString stringWithFormat:@"%d小时前",hour];
            //            [dateFormatter setDateFormat:@"YYYY-MM-dd"];
            //            NSString * need_yMd = [dateFormatter stringFromDate:needFormatDate];
            //            NSString *now_yMd = [dateFormatter stringFromDate:nowDate];
            //
            //            [dateFormatter setDateFormat:@"HH:mm"];
            //            if ([need_yMd isEqualToString:now_yMd]) {
            //                //在同一天
            //                dateStr = [NSString stringWithFormat:@"今天 %@",[dateFormatter stringFromDate:needFormatDate]];
            //            }else{
            //                //昨天
            //                dateStr = [NSString stringWithFormat:@"昨天 %@",[dateFormatter stringFromDate:needFormatDate]];
            //            }
        }else {
            
            [dateFormatter setDateFormat:@"yyyy"];
            NSString * yearStr = [dateFormatter stringFromDate:needFormatDate];
            NSString *nowYear = [dateFormatter stringFromDate:nowDate];
            
            if ([yearStr isEqualToString:nowYear]) {
                //在同一年
                [dateFormatter setDateFormat:@"MM-dd"];
                dateStr = [dateFormatter stringFromDate:needFormatDate];
            }else{
                [dateFormatter setDateFormat:@"yyyy-MM-dd"];
                dateStr = [dateFormatter stringFromDate:needFormatDate];
            }
        }
        
        return dateStr;
    }
    @catch (NSException *exception) {
        return @"";
    }
}

+ (NSString *)formateDate:(NSString *)dateString
{
    @try {
        // ------实例化一个NSDateFormatter对象
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//这里的格式必须和DateString格式一致
        
        NSDate * nowDate = [NSDate date];
        
        // ------将需要转换的时间转换成 NSDate 对象
        NSDate * needFormatDate = [dateFormatter dateFromString:dateString];
        
        // ------取当前时间和转换时间两个日期对象的时间间隔
        NSTimeInterval time = [nowDate timeIntervalSinceDate:needFormatDate];
        
        NSLog(@"time----%f",time);
        // ------再然后，把间隔的秒数折算成天数和小时数：
        
        NSString *dateStr = [[NSString alloc] init];
        
        if (time<=60) {  //1分钟以内的
            
            dateStr = @"刚刚";
            
        }else if(time<=60*60){  //一个小时以内的
            
            int mins = time/60;
            dateStr = [NSString stringWithFormat:@"%d分钟前",mins];
            
        }else if(time<=60*60*24){ //在两天内的
            int hour = time/60/60;
            dateStr = [NSString stringWithFormat:@"%d小时前",hour];
//            [dateFormatter setDateFormat:@"YYYY-MM-dd"];
//            NSString * need_yMd = [dateFormatter stringFromDate:needFormatDate];
//            NSString *now_yMd = [dateFormatter stringFromDate:nowDate];
//
//            [dateFormatter setDateFormat:@"HH:mm"];
//            if ([need_yMd isEqualToString:now_yMd]) {
//                //在同一天
//                dateStr = [NSString stringWithFormat:@"今天 %@",[dateFormatter stringFromDate:needFormatDate]];
//            }else{
//                //昨天
//                dateStr = [NSString stringWithFormat:@"昨天 %@",[dateFormatter stringFromDate:needFormatDate]];
//            }
        }else {
            
            [dateFormatter setDateFormat:@"yyyy"];
            NSString * yearStr = [dateFormatter stringFromDate:needFormatDate];
            NSString *nowYear = [dateFormatter stringFromDate:nowDate];
            
            if ([yearStr isEqualToString:nowYear]) {
                //在同一年
                [dateFormatter setDateFormat:@"MM-dd"];
                dateStr = [dateFormatter stringFromDate:needFormatDate];
            }else{
                [dateFormatter setDateFormat:@"yyyy-MM-dd"];
                dateStr = [dateFormatter stringFromDate:needFormatDate];
            }
        }
        
        return dateStr;
    }
    @catch (NSException *exception) {
        return @"";
    }
}

- (NSString *)capitalLetter{
    if(self.length==0){
        return @"#";
    }
    NSString *firstLetter =[[NSString stringWithFormat:@"%c",pinyinFirstLetter([self characterAtIndex:0])]uppercaseString];
     NSUInteger location = [ALPHA rangeOfString:[firstLetter substringToIndex:1]].location;
    if(location!=NSNotFound){
        return firstLetter;
    }else{
        return @"#";
    }
    return firstLetter;
}

- (NSString *)urlEncode {
    
    NSString *encodedUrl = [self stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    return encodedUrl;
//    return [encodedUrl stringByReplacingOccurrencesOfString:@"+" withString:@"%20"];
    
    
//    NSMutableString *output = [NSMutableString string];
//    const unsigned char *source = (const unsigned char *)[self UTF8String];
//    long sourceLen = strlen((const char *)source);
//    for (int i = 0; i < sourceLen; ++i) {
//        const unsigned char thisChar = source[i];
//        if (thisChar == ' '){
//            [output appendString:@"+"];
//        } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
//                   (thisChar >= 'a' && thisChar <= 'z') ||
//                   (thisChar >= 'A' && thisChar <= 'Z') ||
//                   (thisChar >= '0' && thisChar <= '9')) {
//            [output appendFormat:@"%c", thisChar];
//        } else {
//            [output appendFormat:@"%%%02X", thisChar];
//        }
//    }
//    return output;
}

/** 获取文字CGSize */
+ (CGSize)getSizeWithString:(NSString *)string Font:(UIFont *)font maxSize:(CGSize)maxSize{
    if(!string.length){return CGSizeZero;}
    return [string boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font} context:nil].size;
}

+(BOOL)checkUserID:(NSString *)userID
{
    //长度不为18的都排除掉
    if (userID.length!=18) {
        return NO;
    }
    
    //校验格式
    NSString *regex2 = @"^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    BOOL flag = [identityCardPredicate evaluateWithObject:userID];
    
    if (!flag) {
        return flag;    //格式错误
    }else {
        //格式正确在判断是否合法
        
        //将前17位加权因子保存在数组里
        NSArray * idCardWiArray = @[@"7", @"9", @"10", @"5", @"8", @"4", @"2", @"1", @"6", @"3", @"7", @"9", @"10", @"5", @"8", @"4", @"2"];
        
        //这是除以11后，可能产生的11位余数、验证码，也保存成数组
        NSArray * idCardYArray = @[@"1", @"0", @"10", @"9", @"8", @"7", @"6", @"5", @"4", @"3", @"2"];
        
        //用来保存前17位各自乖以加权因子后的总和
        NSInteger idCardWiSum = 0;
        for(int i = 0;i < 17;i++)
        {
            NSInteger subStrIndex = [[userID substringWithRange:NSMakeRange(i, 1)] integerValue];
            NSInteger idCardWiIndex = [[idCardWiArray objectAtIndex:i] integerValue];
            
            idCardWiSum+= subStrIndex * idCardWiIndex;
            
        }
        
        //计算出校验码所在数组的位置
        NSInteger idCardMod=idCardWiSum%11;
        
        //得到最后一位身份证号码
        NSString * idCardLast= [userID substringWithRange:NSMakeRange(17, 1)];
        
        //如果等于2，则说明校验码是10，身份证号码最后一位应该是X
        if(idCardMod==2)
        {
            if([idCardLast isEqualToString:@"X"]||[idCardLast isEqualToString:@"x"])
            {
                return YES;
            }else
            {
                return NO;
            }
        }else{
            //用计算出的验证码与最后一位身份证号码匹配，如果一致，说明通过，否则是无效的身份证号码
            if([idCardLast isEqualToString: [idCardYArray objectAtIndex:idCardMod]])
            {
                return YES;
            }
            else
            {
                return NO;
            }
        }
    }
}

- (NSString *)keyValueStringWithDict:(NSDictionary *)dict
{
    if (dict == nil) {
        return nil;
    }
    NSMutableString *string = [NSMutableString stringWithString:@"?"];
    [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        [string appendFormat:@"%@=%@&",key,obj];
    }];
    
    if ([string rangeOfString:@"&"].length) {
        [string deleteCharactersInRange:NSMakeRange(string.length - 1, 1)];
    }
    
    return string;
}
+ (NSString *)SC_EncodeUrlInfomWithPhone:(NSString *)phone sharer:(NSString *)sharer{
    
    int phoneLength = (int)phone.length;
    int sharerLength = (int)sharer.length;
    NSMutableString *reversePhone = [NSMutableString stringWithCapacity:phoneLength];
    NSMutableString *reverseSharer = [NSMutableString stringWithCapacity:sharerLength];
    for (int i = phoneLength - 1; i >= 0; i--) {
        unichar c = [phone characterAtIndex:i];
        [reversePhone appendString:[NSString stringWithFormat:@"%c", c]];
    }
    for (int i = sharerLength - 1; i >= 0; i--) {
        unichar c = [sharer characterAtIndex:i];
        [reverseSharer appendString:[NSString stringWithFormat:@"%c", c]];
    }
    NSString *infoStr = [NSString stringWithFormat:@"%@,%@",reversePhone,reverseSharer];
    unichar checkCode = 0x00;
    for (int i = 0; i<infoStr.length-1; i++) {
        unichar c = [infoStr characterAtIndex:i];
        if(i==0){
            checkCode = c;
        }else{
            checkCode = checkCode^c;
        }
    }
    NSString *compenents = [NSString stringWithFormat:@"%@,%@,%@",reversePhone,reverseSharer,@(checkCode)];
    return compenents;
}

+ (BOOL)isValidatedLicense:(NSString *)license;{
    if([self SC_isBlankString:license])return NO;
    license = [self SC_trimString:license];
    NSString *licenseRegex = @"^[a-zA-Z0-9]{0,20}$";
    NSPredicate *licensePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",licenseRegex];
    return [licensePredicate evaluateWithObject:license];
}

+ (NSString *)addressStringWithProvinceName:(NSString *)provinceName cityName:(NSString *)cityName area:(NSString *)area detailAddress:(NSString *)detailAddress{
    NSMutableString *address = [[NSMutableString alloc] init];
    if(![NSString SC_isBlankString:provinceName]){
        [address appendString:provinceName];
    }
    if(![NSString SC_isBlankString:cityName]){
        if(provinceName.length&&[cityName containsString:provinceName]){
            [address deleteCharactersInRange:NSMakeRange(0, provinceName.length)];
            [address appendString:cityName];
        }else{
            [address appendString:cityName];
        }
    }
    if(![NSString SC_isBlankString:area]){
        [address appendString:area];
    }
    if(![NSString SC_isBlankString:detailAddress]){
        [address appendString:detailAddress];
    }
    return address;
}

+ (NSString *)brandStringWithBrandName:(NSString *)brandName seriesName:(NSString *)seriesName speciesName:(NSString *)speciesName{
    NSMutableString *name = [NSMutableString string];
    if(speciesName.length){
        if(seriesName.length){
            [name appendString:seriesName];
        }
        [name appendString:speciesName];
    }else if (seriesName.length){
        [name appendString:seriesName];
    }else if(brandName.length){
        [name appendString:brandName];
    }
    return name;
}
+ (NSString *)requiredStringWithBrandName:(NSString *)brandName seriesName:(NSString *)seriesName speciesName:(NSString *)speciesName;{
    NSMutableString *name = [NSMutableString string];
    if (seriesName.length){
        [name appendString:seriesName];
    }else if(brandName.length){
        [name appendString:brandName];
    }
    return name;
}

- (NSString *)sc_trimFloatZero{
    return [self stringByReplacingOccurrencesOfString:@".00" withString:@""];
}
//获取经销商 简称
- (NSString *)merchantAbbreviation {
    NSString *merchanName = self;
    
    if ([self containsString:@"("]) {
        NSArray *nameArr = [self componentsSeparatedByString:@"("];
        merchanName = nameArr.lastObject;
        if ([merchanName hasSuffix:@")"]) {
            merchanName = [merchanName substringToIndex:merchanName.length-1];
        }
    }
    return merchanName;
}

+ (NSMutableAttributedString *)merchantMemberLevel:(NSInteger)memberLevel withName:(NSString *)name {
    if (!name) {
        name = @"";
    } else {
        name = [NSString stringWithFormat:@"  %@",name];
    }
    NSMutableAttributedString *nameAttr = [[NSMutableAttributedString alloc] initWithString:name];
    NSString *img;
    if (memberLevel >= SCMemberVipLevel1) {
        if (memberLevel == SCMemberVipLevel1) {
            img = @"vip_icon_lianmeng";
        } else if (memberLevel == SCMemberVipLevel2) {
            img = @"vip_icon_chengxin";
        } else if (memberLevel == SCMemberVipLevel3) {
            img = @"vip_icon_yanxuan";
        }
        NSTextAttachment *attach = [[NSTextAttachment alloc] init];
        attach.image = [UIImage imageNamed:img];
        attach.bounds = CGRectMake(0, -5, 20, 22);
        NSAttributedString *attchAttr = [NSAttributedString attributedStringWithAttachment:attach];
        NSMutableAttributedString *matt = [[NSMutableAttributedString alloc] initWithAttributedString:attchAttr];
        [matt appendAttributedString:nameAttr];
        return matt;
    }
    return nameAttr;
}

+ (NSString *)urlForShareListWithParam:(NSMutableDictionary *)param {
    
    NSString *paramString = nil;
    if(param){
//        [param setValue:[[NSUserDefaults standardUserDefaults]objectForKey:kUserId] forKey:@"userId"];
//        [param setValue:@([Config sharedConfig].user.merchantId) forKey:@"shareMerchantId"];
//        [param setValue:@([Config sharedConfig].user.userId) forKey:@"shareUserId"];
        NSData *data = [NSJSONSerialization dataWithJSONObject:param options:0 error:nil];
        paramString = [[NSString alloc] initWithData:[data base64EncodedDataWithOptions:0] encoding:4];
    }
    
    NSString *urlBase = sc_url_web(@"/sharecarlist");
    if (paramString) {
        urlBase = [urlBase stringByAppendingFormat:@"?params=%@",paramString];
    }
    return [urlBase urlEncode];
}

@end
